package com.itheima.service.impl;

import com.itheima.mapper.ReportMapper;
import com.itheima.mapper.SetMealMapper;
import com.itheima.resources.DateUtils;
import com.itheima.service.ReportService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMapper reportMapper;

    @Autowired
    private SetMealMapper setMealMapper;


    @Override
    public List<Map> getSetMealReport() {
        //调用持久层
        return setMealMapper.getSetMealReport();

    }

    @Override
    public Map getBusinessData() {
        //调用持久层查询数据库
        //查询热门套餐
        List<Map> list=reportMapper.getHotSetmeal();

        //今日日期
        String today = DateUtils.parseDate2String(new Date(), "yyyy-MM-dd");
        //今日新增会员数
        int todayNewMember=reportMapper.getTodayNewMember(today,today);

        //总会员数
        int totalMember=reportMapper.getTotalMember();

        //本周新增会员数
        String weekStartDay = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());//获取本周第一天
        String weekEndDay = DateUtils.parseDate2String(DateUtils.getSundayOfThisWeek());//获取本周最后一天
        System.out.println("本周第一天:"+weekStartDay);
        System.out.println("本周最后一天:"+weekEndDay);
        int thisWeekNewMember = reportMapper.getTodayNewMember(weekStartDay, weekEndDay);

        //本月新增会员数
        String monthStartDay = DateUtils.parseDate2String(DateUtils.getFirstDay4CurrentMonth());//获取本月第一天
        String monthEndDay = DateUtils.parseDate2String(DateUtils.getLastDayOfMonth(new Date()));//获取本月最后一天
        System.out.println("本月第一天:"+monthStartDay);
        System.out.println("本月最后一天:"+monthEndDay);
        int thisMonthNewMember = reportMapper.getTodayNewMember(monthStartDay, monthEndDay);

        //今日预约数
        int todayOrderNumber = reportMapper.getOrderNumber(today,today);

        //本周预约数
        int thisWeekOrderNumber = reportMapper.getOrderNumber(weekStartDay,weekEndDay);

        //本月预约数
        int thisMonthOrderNumber = reportMapper.getOrderNumber(monthStartDay,monthEndDay);

        //今日到诊数
        int todayVisitsNumber = reportMapper.getVisitsNumber(today,today);
        //本周到诊数
        int thisWeekVisitsNumber = reportMapper.getVisitsNumber(weekStartDay,weekEndDay);
        //本月到诊数
        int thisMonthVisitsNumber = reportMapper.getVisitsNumber(monthStartDay,monthEndDay);


        Map map = new HashMap<>();
        map.put("hotSetmeal",list);//显示4个热门套餐
        map.put("reportDate",today);//日期
        map.put("todayNewMember",todayNewMember);//今日新增会员数
        map.put("totalMember",totalMember);//总会员数
        map.put("thisWeekNewMember",thisWeekNewMember);//本周新增会员数
        map.put("thisMonthNewMember",thisMonthNewMember);//本月新增会员数
        map.put("todayOrderNumber",todayOrderNumber);//今日预约数
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);//本周预约数
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);//本月预约数
        map.put("todayVisitsNumber",todayVisitsNumber);//今日到诊数
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);//本周到诊数
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);//本月到诊数

        return map;
    }
}
